/**
 * UserDaoImpl.java
 * cn.feigme.dao.impl
 * @author Feigme 
 * 2007-8-27
 */
package cn.feigme.identity.dao.impl;

import java.util.List;

import org.apache.lucene.analysis.StopAnalyzer;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.queryParser.MultiFieldQueryParser;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.search.Query;
import org.hibernate.search.FullTextQuery;
import org.hibernate.search.FullTextSession;
import org.hibernate.search.Search;

import cn.feigme.base.dao.impl.GenericDaoHibernateImpl;
import cn.feigme.identity.dao.UserDao;
import cn.feigme.identity.model.User;



/**
 * @author Feigme 
 *
 */
public class UserDaoImpl extends GenericDaoHibernateImpl<User, String> implements UserDao {
	
	/**
	 * method 1
	 * 必须要有空构造函数
	 * 并且指明他泛型的具体的类
	 */
//	public UserDaoImpl() {
//		super(User.class);
//	}
	
	@SuppressWarnings("unchecked")
	public List<User> getUsersByExample(User user) {
		
		return this.getHibernateTemplate().findByExample(user);
	}

	public List testLucene(String str) throws ParseException {
		MultiFieldQueryParser  parser = new MultiFieldQueryParser ( new String[]{"name", "answer"}, new StandardAnalyzer());
		Query luceneQuery = parser.parse(str);
		FullTextSession s = Search.createFullTextSession(getSession());
		FullTextQuery query = s.createFullTextQuery(luceneQuery, User.class);
		List result = query.list();

		return result;
	}

	public User getUserByName(String emailName) {
		User user = new User();
		user.setEmail(emailName);
		List<User> list = this.getUsersByExample(user);
		if(list!=null && !list.isEmpty()){
			return list.get(0);
		}else{
			return null;
		}
	}
	
	
	
}
